
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 04/10/2011 22:06:55
-- Generated from EDMX file: E:\workgroup\xTeam\xTeamSHE\xTeam.Hengle.DataAccess\DataBase.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [xTeamSHE];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_GuestBook_Product]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[GuestBook] DROP CONSTRAINT [FK_GuestBook_Product];
GO
IF OBJECT_ID(N'[dbo].[FK_News_Classify]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[News] DROP CONSTRAINT [FK_News_Classify];
GO
IF OBJECT_ID(N'[xTeamSHEStoreContainer].[FK_Order_Sale_User]', 'F') IS NOT NULL
    ALTER TABLE [xTeamSHEStoreContainer].[Order_Sale] DROP CONSTRAINT [FK_Order_Sale_User];
GO
IF OBJECT_ID(N'[dbo].[FK_Product_Classify]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Product] DROP CONSTRAINT [FK_Product_Classify];
GO
IF OBJECT_ID(N'[xTeamSHEStoreContainer].[FK_Product_Details_Product]', 'F') IS NOT NULL
    ALTER TABLE [xTeamSHEStoreContainer].[Product_Details] DROP CONSTRAINT [FK_Product_Details_Product];
GO
IF OBJECT_ID(N'[xTeamSHEStoreContainer].[FK_Product_Discount_Product]', 'F') IS NOT NULL
    ALTER TABLE [xTeamSHEStoreContainer].[Product_Discount] DROP CONSTRAINT [FK_Product_Discount_Product];
GO
IF OBJECT_ID(N'[xTeamSHEStoreContainer].[FK_Product_Discount_User_Level]', 'F') IS NOT NULL
    ALTER TABLE [xTeamSHEStoreContainer].[Product_Discount] DROP CONSTRAINT [FK_Product_Discount_User_Level];
GO
IF OBJECT_ID(N'[dbo].[FK_Product_Extend_Product]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Product_Extend] DROP CONSTRAINT [FK_Product_Extend_Product];
GO
IF OBJECT_ID(N'[dbo].[FK_Product_Image_Product]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Product_Image] DROP CONSTRAINT [FK_Product_Image_Product];
GO
IF OBJECT_ID(N'[dbo].[FK_User_Address_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[User_Address] DROP CONSTRAINT [FK_User_Address_User];
GO
IF OBJECT_ID(N'[xTeamSHEStoreContainer].[FK_User_UserInLevel_User]', 'F') IS NOT NULL
    ALTER TABLE [xTeamSHEStoreContainer].[User_UserInLevel] DROP CONSTRAINT [FK_User_UserInLevel_User];
GO
IF OBJECT_ID(N'[xTeamSHEStoreContainer].[FK_User_UserInLevel_User_Level]', 'F') IS NOT NULL
    ALTER TABLE [xTeamSHEStoreContainer].[User_UserInLevel] DROP CONSTRAINT [FK_User_UserInLevel_User_Level];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[xTeamSHEStoreContainer].[Advertise]', 'U') IS NOT NULL
    DROP TABLE [xTeamSHEStoreContainer].[Advertise];
GO
IF OBJECT_ID(N'[dbo].[Classify]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Classify];
GO
IF OBJECT_ID(N'[dbo].[GuestBook]', 'U') IS NOT NULL
    DROP TABLE [dbo].[GuestBook];
GO
IF OBJECT_ID(N'[dbo].[News]', 'U') IS NOT NULL
    DROP TABLE [dbo].[News];
GO
IF OBJECT_ID(N'[xTeamSHEStoreContainer].[Order_Details]', 'U') IS NOT NULL
    DROP TABLE [xTeamSHEStoreContainer].[Order_Details];
GO
IF OBJECT_ID(N'[xTeamSHEStoreContainer].[Order_Sale]', 'U') IS NOT NULL
    DROP TABLE [xTeamSHEStoreContainer].[Order_Sale];
GO
IF OBJECT_ID(N'[xTeamSHEStoreContainer].[Order_Sale_Address]', 'U') IS NOT NULL
    DROP TABLE [xTeamSHEStoreContainer].[Order_Sale_Address];
GO
IF OBJECT_ID(N'[xTeamSHEStoreContainer].[Order_Sale_Express]', 'U') IS NOT NULL
    DROP TABLE [xTeamSHEStoreContainer].[Order_Sale_Express];
GO
IF OBJECT_ID(N'[dbo].[Product]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Product];
GO
IF OBJECT_ID(N'[xTeamSHEStoreContainer].[Product_Details]', 'U') IS NOT NULL
    DROP TABLE [xTeamSHEStoreContainer].[Product_Details];
GO
IF OBJECT_ID(N'[xTeamSHEStoreContainer].[Product_Discount]', 'U') IS NOT NULL
    DROP TABLE [xTeamSHEStoreContainer].[Product_Discount];
GO
IF OBJECT_ID(N'[dbo].[Product_Extend]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Product_Extend];
GO
IF OBJECT_ID(N'[dbo].[Product_Image]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Product_Image];
GO
IF OBJECT_ID(N'[xTeamSHEStoreContainer].[ShopCar]', 'U') IS NOT NULL
    DROP TABLE [xTeamSHEStoreContainer].[ShopCar];
GO
IF OBJECT_ID(N'[dbo].[User]', 'U') IS NOT NULL
    DROP TABLE [dbo].[User];
GO
IF OBJECT_ID(N'[dbo].[User_Address]', 'U') IS NOT NULL
    DROP TABLE [dbo].[User_Address];
GO
IF OBJECT_ID(N'[dbo].[User_Level]', 'U') IS NOT NULL
    DROP TABLE [dbo].[User_Level];
GO
IF OBJECT_ID(N'[xTeamSHEStoreContainer].[User_UserInLevel]', 'U') IS NOT NULL
    DROP TABLE [xTeamSHEStoreContainer].[User_UserInLevel];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Advertise'
CREATE TABLE [dbo].[Advertise] (
    [Aid] int IDENTITY(1,1) NOT NULL,
    [Title] nvarchar(50)  NOT NULL,
    [Type] int  NOT NULL,
    [Contents] nvarchar(4000)  NOT NULL,
    [Description] nvarchar(50)  NOT NULL,
    [Sequence] int  NOT NULL,
    [ExtendKey] nvarchar(50)  NULL,
    [ModuleKey] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'Classify'
CREATE TABLE [dbo].[Classify] (
    [ClassifyId] int IDENTITY(1,1) NOT NULL,
    [Title] nvarchar(50)  NOT NULL,
    [KeyWords] nvarchar(255)  NULL,
    [Description] nvarchar(500)  NULL,
    [ParentId] int  NOT NULL,
    [Path] varchar(1000)  NULL,
    [Childs] int  NOT NULL,
    [Sequence] int  NOT NULL,
    [Floor] int  NOT NULL,
    [ModuleKey] nvarchar(50)  NOT NULL,
    [Redirect] nvarchar(500)  NULL
);
GO

-- Creating table 'GuestBook'
CREATE TABLE [dbo].[GuestBook] (
    [GuestBookId] int IDENTITY(1,1) NOT NULL,
    [NickName] nvarchar(20)  NOT NULL,
    [Email] nvarchar(50)  NOT NULL,
    [Content] nvarchar(500)  NOT NULL,
    [ReContent] nvarchar(500)  NULL,
    [AddDate] datetime  NOT NULL,
    [Product_ProductId] int  NOT NULL
);
GO

-- Creating table 'News'
CREATE TABLE [dbo].[News] (
    [NewsId] int IDENTITY(1,1) NOT NULL,
    [Title] nvarchar(500)  NOT NULL,
    [Keywords] nvarchar(500)  NULL,
    [Description] nvarchar(500)  NULL,
    [Contents] nvarchar(max)  NULL,
    [Author] nvarchar(50)  NULL,
    [Source] nvarchar(125)  NULL,
    [AddDateTime] datetime  NOT NULL,
    [ClickCount] int  NOT NULL,
    [Isvalid] bit  NOT NULL,
    [Sequence] int  NOT NULL,
    [eTag] nvarchar(50)  NULL,
    [Classify_ClassifyId] int  NOT NULL
);
GO

-- Creating table 'Order_Details'
CREATE TABLE [dbo].[Order_Details] (
    [OrderId] nvarchar(50)  NOT NULL,
    [Property] nvarchar(4000)  NULL,
    [Count] int  NOT NULL,
    [Discount] float  NOT NULL,
    [Price] decimal(7,2)  NOT NULL,
    [Description] nvarchar(50)  NULL,
    [ProductId] int  NOT NULL
);
GO

-- Creating table 'Order_Sale'
CREATE TABLE [dbo].[Order_Sale] (
    [SaleId] nvarchar(50)  NOT NULL,
    [AddDate] datetime  NOT NULL,
    [Description] nvarchar(50)  NULL,
    [State] int  NOT NULL,
    [AddRessId] int  NOT NULL,
    [Uid] int  NOT NULL
);
GO

-- Creating table 'Order_Sale_Address'
CREATE TABLE [dbo].[Order_Sale_Address] (
    [ReallyName] nvarchar(50)  NOT NULL,
    [Address] nvarchar(50)  NOT NULL,
    [Mobile] nvarchar(50)  NULL,
    [Phone] nvarchar(50)  NULL,
    [PostNo] nvarchar(50)  NULL,
    [Description] nvarchar(50)  NULL,
    [SaleId] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'Product'
CREATE TABLE [dbo].[Product] (
    [ProductId] int IDENTITY(1,1) NOT NULL,
    [ProductName] nvarchar(255)  NOT NULL,
    [SubName] nvarchar(50)  NULL,
    [Description] nvarchar(255)  NULL,
    [KeyWords] nvarchar(500)  NULL,
    [Price] decimal(7,2)  NOT NULL,
    [Hits] int  NOT NULL,
    [ReplyCount] int  NOT NULL,
    [AddDateTime] datetime  NOT NULL,
    [IsActive] bit  NOT NULL,
    [ProductNo] nvarchar(20)  NULL,
    [Status] int  NOT NULL,
    [Discount] float  NOT NULL,
    [StockCount] int  NOT NULL,
    [Classify_ClassifyId] int  NOT NULL
);
GO

-- Creating table 'Product_Details'
CREATE TABLE [dbo].[Product_Details] (
    [Detail] nvarchar(4000)  NULL,
    [Services] nvarchar(4000)  NULL,
    [PackList] nvarchar(4000)  NULL,
    [FullSnap] nvarchar(4000)  NULL,
    [Description] nvarchar(4000)  NULL,
    [ProductId] int  NOT NULL
);
GO

-- Creating table 'Product_Discount'
CREATE TABLE [dbo].[Product_Discount] (
    [LevelId] int  NOT NULL,
    [Discount] float  NOT NULL,
    [IsDiscount] bit  NOT NULL,
    [ProductId] int  NOT NULL
);
GO

-- Creating table 'Product_Extend'
CREATE TABLE [dbo].[Product_Extend] (
    [ExtendId] int IDENTITY(1,1) NOT NULL,
    [ExtendKey] nvarchar(50)  NOT NULL,
    [ExtendValue] nvarchar(1000)  NOT NULL,
    [Sequence] int  NOT NULL,
    [Product_ProductId] int  NOT NULL
);
GO

-- Creating table 'Product_Image'
CREATE TABLE [dbo].[Product_Image] (
    [ImageId] int IDENTITY(1,1) NOT NULL,
    [ImageName] nvarchar(50)  NOT NULL,
    [Title] nvarchar(255)  NULL,
    [Description] nvarchar(1000)  NULL,
    [IsCover] bit  NOT NULL,
    [Sequence] int  NOT NULL,
    [Product_ProductId] int  NOT NULL
);
GO

-- Creating table 'ShopCar'
CREATE TABLE [dbo].[ShopCar] (
    [AddDate] datetime  NOT NULL,
    [Count] int  NOT NULL,
    [Property] varchar(4000)  NULL,
    [type] int  NOT NULL,
    [Description] nvarchar(50)  NULL,
    [Uid] int  NOT NULL,
    [ProductId] int  NOT NULL
);
GO

-- Creating table 'User'
CREATE TABLE [dbo].[User] (
    [Uid] int IDENTITY(1,1) NOT NULL,
    [Uname] nvarchar(50)  NOT NULL,
    [Password] nvarchar(50)  NOT NULL,
    [NickName] nvarchar(50)  NOT NULL,
    [MobilePhone] nvarchar(20)  NULL,
    [Phone] nvarchar(20)  NULL,
    [QQ] nvarchar(50)  NULL,
    [Ali] nvarchar(50)  NULL,
    [Msn] nvarchar(50)  NULL,
    [RegTime] datetime  NOT NULL,
    [Enabled] int  NOT NULL,
    [Face] nvarchar(50)  NULL
);
GO

-- Creating table 'User_Address'
CREATE TABLE [dbo].[User_Address] (
    [AddressId] int IDENTITY(1,1) NOT NULL,
    [ReallyName] nvarchar(50)  NOT NULL,
    [Address] nvarchar(50)  NOT NULL,
    [Mobile] nvarchar(50)  NULL,
    [Phone] nvarchar(50)  NULL,
    [PostNo] nvarchar(50)  NULL,
    [Description] nvarchar(50)  NULL,
    [User_Uid] int  NOT NULL
);
GO

-- Creating table 'User_Level'
CREATE TABLE [dbo].[User_Level] (
    [LevelId] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [MinValue] int  NOT NULL,
    [Icon] nvarchar(50)  NOT NULL,
    [Discount] float  NOT NULL,
    [IsDiscount] bit  NOT NULL
);
GO

-- Creating table 'Order_Sale_Express'
CREATE TABLE [dbo].[Order_Sale_Express] (
    [ExpressNo] nvarchar(50)  NOT NULL,
    [Description] nvarchar(500)  NULL,
    [ExpressType] int  NOT NULL,
    [SaleId] nvarchar(50)  NOT NULL,
    [addDate] datetime  NOT NULL
);
GO

-- Creating table 'User_UserInLevel'
CREATE TABLE [dbo].[User_UserInLevel] (
    [User_Uid] int  NOT NULL,
    [User_Level_LevelId] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Aid], [Title], [Type], [Contents], [Description], [Sequence], [ModuleKey] in table 'Advertise'
ALTER TABLE [dbo].[Advertise]
ADD CONSTRAINT [PK_Advertise]
    PRIMARY KEY CLUSTERED ([Aid], [Title], [Type], [Contents], [Description], [Sequence], [ModuleKey] ASC);
GO

-- Creating primary key on [ClassifyId] in table 'Classify'
ALTER TABLE [dbo].[Classify]
ADD CONSTRAINT [PK_Classify]
    PRIMARY KEY CLUSTERED ([ClassifyId] ASC);
GO

-- Creating primary key on [GuestBookId] in table 'GuestBook'
ALTER TABLE [dbo].[GuestBook]
ADD CONSTRAINT [PK_GuestBook]
    PRIMARY KEY CLUSTERED ([GuestBookId] ASC);
GO

-- Creating primary key on [NewsId] in table 'News'
ALTER TABLE [dbo].[News]
ADD CONSTRAINT [PK_News]
    PRIMARY KEY CLUSTERED ([NewsId] ASC);
GO

-- Creating primary key on [OrderId], [Count], [Discount], [Price], [ProductId] in table 'Order_Details'
ALTER TABLE [dbo].[Order_Details]
ADD CONSTRAINT [PK_Order_Details]
    PRIMARY KEY CLUSTERED ([OrderId], [Count], [Discount], [Price], [ProductId] ASC);
GO

-- Creating primary key on [SaleId], [AddDate], [State], [AddRessId], [Uid] in table 'Order_Sale'
ALTER TABLE [dbo].[Order_Sale]
ADD CONSTRAINT [PK_Order_Sale]
    PRIMARY KEY CLUSTERED ([SaleId], [AddDate], [State], [AddRessId], [Uid] ASC);
GO

-- Creating primary key on [ReallyName], [Address], [SaleId] in table 'Order_Sale_Address'
ALTER TABLE [dbo].[Order_Sale_Address]
ADD CONSTRAINT [PK_Order_Sale_Address]
    PRIMARY KEY CLUSTERED ([ReallyName], [Address], [SaleId] ASC);
GO

-- Creating primary key on [ProductId] in table 'Product'
ALTER TABLE [dbo].[Product]
ADD CONSTRAINT [PK_Product]
    PRIMARY KEY CLUSTERED ([ProductId] ASC);
GO

-- Creating primary key on [ProductId] in table 'Product_Details'
ALTER TABLE [dbo].[Product_Details]
ADD CONSTRAINT [PK_Product_Details]
    PRIMARY KEY CLUSTERED ([ProductId] ASC);
GO

-- Creating primary key on [LevelId], [Discount], [IsDiscount], [ProductId] in table 'Product_Discount'
ALTER TABLE [dbo].[Product_Discount]
ADD CONSTRAINT [PK_Product_Discount]
    PRIMARY KEY CLUSTERED ([LevelId], [Discount], [IsDiscount], [ProductId] ASC);
GO

-- Creating primary key on [ExtendId] in table 'Product_Extend'
ALTER TABLE [dbo].[Product_Extend]
ADD CONSTRAINT [PK_Product_Extend]
    PRIMARY KEY CLUSTERED ([ExtendId] ASC);
GO

-- Creating primary key on [ImageId] in table 'Product_Image'
ALTER TABLE [dbo].[Product_Image]
ADD CONSTRAINT [PK_Product_Image]
    PRIMARY KEY CLUSTERED ([ImageId] ASC);
GO

-- Creating primary key on [AddDate], [Count], [type], [Uid], [ProductId] in table 'ShopCar'
ALTER TABLE [dbo].[ShopCar]
ADD CONSTRAINT [PK_ShopCar]
    PRIMARY KEY CLUSTERED ([AddDate], [Count], [type], [Uid], [ProductId] ASC);
GO

-- Creating primary key on [Uid] in table 'User'
ALTER TABLE [dbo].[User]
ADD CONSTRAINT [PK_User]
    PRIMARY KEY CLUSTERED ([Uid] ASC);
GO

-- Creating primary key on [AddressId] in table 'User_Address'
ALTER TABLE [dbo].[User_Address]
ADD CONSTRAINT [PK_User_Address]
    PRIMARY KEY CLUSTERED ([AddressId] ASC);
GO

-- Creating primary key on [LevelId] in table 'User_Level'
ALTER TABLE [dbo].[User_Level]
ADD CONSTRAINT [PK_User_Level]
    PRIMARY KEY CLUSTERED ([LevelId] ASC);
GO

-- Creating primary key on [ExpressNo], [ExpressType], [SaleId], [addDate] in table 'Order_Sale_Express'
ALTER TABLE [dbo].[Order_Sale_Express]
ADD CONSTRAINT [PK_Order_Sale_Express]
    PRIMARY KEY CLUSTERED ([ExpressNo], [ExpressType], [SaleId], [addDate] ASC);
GO

-- Creating primary key on [User_Uid], [User_Level_LevelId] in table 'User_UserInLevel'
ALTER TABLE [dbo].[User_UserInLevel]
ADD CONSTRAINT [PK_User_UserInLevel]
    PRIMARY KEY NONCLUSTERED ([User_Uid], [User_Level_LevelId] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Classify_ClassifyId] in table 'News'
ALTER TABLE [dbo].[News]
ADD CONSTRAINT [FK_News_Classify]
    FOREIGN KEY ([Classify_ClassifyId])
    REFERENCES [dbo].[Classify]
        ([ClassifyId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_News_Classify'
CREATE INDEX [IX_FK_News_Classify]
ON [dbo].[News]
    ([Classify_ClassifyId]);
GO

-- Creating foreign key on [Classify_ClassifyId] in table 'Product'
ALTER TABLE [dbo].[Product]
ADD CONSTRAINT [FK_Product_Classify]
    FOREIGN KEY ([Classify_ClassifyId])
    REFERENCES [dbo].[Classify]
        ([ClassifyId])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Product_Classify'
CREATE INDEX [IX_FK_Product_Classify]
ON [dbo].[Product]
    ([Classify_ClassifyId]);
GO

-- Creating foreign key on [Product_ProductId] in table 'GuestBook'
ALTER TABLE [dbo].[GuestBook]
ADD CONSTRAINT [FK_GuestBook_Product]
    FOREIGN KEY ([Product_ProductId])
    REFERENCES [dbo].[Product]
        ([ProductId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_GuestBook_Product'
CREATE INDEX [IX_FK_GuestBook_Product]
ON [dbo].[GuestBook]
    ([Product_ProductId]);
GO

-- Creating foreign key on [Uid] in table 'Order_Sale'
ALTER TABLE [dbo].[Order_Sale]
ADD CONSTRAINT [FK_Order_Sale_User]
    FOREIGN KEY ([Uid])
    REFERENCES [dbo].[User]
        ([Uid])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Order_Sale_User'
CREATE INDEX [IX_FK_Order_Sale_User]
ON [dbo].[Order_Sale]
    ([Uid]);
GO

-- Creating foreign key on [ProductId] in table 'Product_Details'
ALTER TABLE [dbo].[Product_Details]
ADD CONSTRAINT [FK_Product_Details_Product]
    FOREIGN KEY ([ProductId])
    REFERENCES [dbo].[Product]
        ([ProductId])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [ProductId] in table 'Product_Discount'
ALTER TABLE [dbo].[Product_Discount]
ADD CONSTRAINT [FK_Product_Discount_Product]
    FOREIGN KEY ([ProductId])
    REFERENCES [dbo].[Product]
        ([ProductId])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Product_Discount_Product'
CREATE INDEX [IX_FK_Product_Discount_Product]
ON [dbo].[Product_Discount]
    ([ProductId]);
GO

-- Creating foreign key on [Product_ProductId] in table 'Product_Extend'
ALTER TABLE [dbo].[Product_Extend]
ADD CONSTRAINT [FK_Product_Extend_Product]
    FOREIGN KEY ([Product_ProductId])
    REFERENCES [dbo].[Product]
        ([ProductId])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Product_Extend_Product'
CREATE INDEX [IX_FK_Product_Extend_Product]
ON [dbo].[Product_Extend]
    ([Product_ProductId]);
GO

-- Creating foreign key on [Product_ProductId] in table 'Product_Image'
ALTER TABLE [dbo].[Product_Image]
ADD CONSTRAINT [FK_Product_Image_Product]
    FOREIGN KEY ([Product_ProductId])
    REFERENCES [dbo].[Product]
        ([ProductId])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Product_Image_Product'
CREATE INDEX [IX_FK_Product_Image_Product]
ON [dbo].[Product_Image]
    ([Product_ProductId]);
GO

-- Creating foreign key on [LevelId] in table 'Product_Discount'
ALTER TABLE [dbo].[Product_Discount]
ADD CONSTRAINT [FK_Product_Discount_User_Level]
    FOREIGN KEY ([LevelId])
    REFERENCES [dbo].[User_Level]
        ([LevelId])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [User_Uid] in table 'User_Address'
ALTER TABLE [dbo].[User_Address]
ADD CONSTRAINT [FK_User_Address_User]
    FOREIGN KEY ([User_Uid])
    REFERENCES [dbo].[User]
        ([Uid])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_User_Address_User'
CREATE INDEX [IX_FK_User_Address_User]
ON [dbo].[User_Address]
    ([User_Uid]);
GO

-- Creating foreign key on [User_Uid] in table 'User_UserInLevel'
ALTER TABLE [dbo].[User_UserInLevel]
ADD CONSTRAINT [FK_User_UserInLevel_User]
    FOREIGN KEY ([User_Uid])
    REFERENCES [dbo].[User]
        ([Uid])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [User_Level_LevelId] in table 'User_UserInLevel'
ALTER TABLE [dbo].[User_UserInLevel]
ADD CONSTRAINT [FK_User_UserInLevel_User_Level]
    FOREIGN KEY ([User_Level_LevelId])
    REFERENCES [dbo].[User_Level]
        ([LevelId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_User_UserInLevel_User_Level'
CREATE INDEX [IX_FK_User_UserInLevel_User_Level]
ON [dbo].[User_UserInLevel]
    ([User_Level_LevelId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------